<?php

namespace app\admin\controller;

use app\BaseController;
use think\facade\Db;
use think\App;

class Taskmetafields extends BaseController
{

    protected $model = null; 

    public function __construct(App $app)
    {
        parent::__construct($app);
    }
    
    // http://erp.back.cn/admin/Taskmetafields/addmetafields
    /**
    * 方法详情
    * @param array params
    */
    public function addmetafields()
    {
        $site = table('site')
            ->where('id',37)
            ->find();
        $customers = table('customer')
            ->where('id',693950)
            // ->where('id',2101)
            ->find();
        date_default_timezone_set('Asia/Shanghai');
        $url = $site['site_url'] . "/admin/api/2023-07/customers/".$customers['customer_id']."/metafields.json";
        $arr = array();
        $arr['metafield']['namespace'] = 'global';
        $arr['metafield']['key'] =  'new';
        $arr['metafield']['value'] = 'newvalue';
        $arr['metafield']['type'] = 'single_line_text_field';
        $data2 = posturl($url, $arr, $site);
        $data = json_decode($data2, true);
        halt($data);
    }
    
    // http://erp.back.cn/admin/Taskmetafields/findmetafields
    /**
    * 方法详情
    * @param array params
    */
    public function findmetafields()
    {
        $site = table('site')
            ->where('id',37)
            ->find();
        $customers = table('customer')
            ->where('id',693950)
            // ->where('id',2101)
            ->find();
        date_default_timezone_set('Asia/Shanghai');
        $url = $site['site_url'] . "/admin/api/2023-07/customers/".$customers['customer_id']."/metafields.json";   
        $data2 =  geturl($url, $site['apikey'], $site['apisecret']);
        $data = json_decode($data2, true);
        halt($data);
    }
}
